from sqlalchemy import Column, Integer, String, ForeignKey,DateTime
from sqlalchemy.orm import relationship
from core.base.orm_model import Base, TimestampMixin
from datetime import datetime

class Dictionary(Base, TimestampMixin):
    __tablename__ = "dictionary"

    id = Column(Integer, primary_key=True, index=True)
    dict_key = Column(String(50), nullable=False, comment='字典键')
    dict_value = Column(String(100), nullable=False, comment='字典值')
    dict_type = Column(String(50), ForeignKey("dict_type.type_code"), nullable=False, comment='字典类型')
    category = Column(String(50), nullable=True, comment='分类')      
    score = Column(Integer, default=0, comment='得分')        
    options = Column(String(200), nullable=True, comment='选项', default='N' )          
    sort_order = Column(Integer, default=0, comment='排序')
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment="更新时间")

    dict_type_rel = relationship("DictType", back_populates="items")

    def __repr__(self):
        return f"<Dictionary {self.dict_key}:{self.dict_value}>"